package cn.yunyichina.provider.pay.alipay.service;

import cn.yunyichina.provider.pay.alipay.entity.TradeFailure;
import com.alipay.api.AlipayResponse;

/**
 * Created by Lullaby on 2016/11/14.
 */
public class BaseTradeService extends BaseService {

    protected TradeFailure getTradeFailureResponse(AlipayResponse alipayResponse) {
        TradeFailure failure = new TradeFailure();

        failure.setCode(alipayResponse.getCode());
        failure.setMsg(alipayResponse.getMsg());
        failure.setSubCode(alipayResponse.getSubCode());
        failure.setSubMsg(alipayResponse.getSubMsg());

        return failure;
    }

    protected <T extends cn.yunyichina.provider.iface.entity.alipay.AlipayResponse> T setCodeAndMessage
            (AlipayResponse alipayResponse, Class<T> clazz) throws IllegalAccessException, InstantiationException {
        T instance = clazz.newInstance();
        instance.setCode(alipayResponse.getCode());
        instance.setMsg(alipayResponse.getMsg());
        instance.setSubCode(alipayResponse.getSubCode());
        instance.setSubMsg(alipayResponse.getSubMsg());

        return instance;
    }

}
